import urllib.request

url = 'http://www.baidu.com'
# 用字典来构建 headers
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) \
        AppleWebKit/537.36(KHTML, like Gecko) \
        Chrome/70.0.3538.110 Safari/537.36'
}
# 构建请求对象
request = urllib.request.Request(url = url, headers = headers)
# 发送请求
response = urllib.request.urlopen(request)

print(response.read().decode())

